﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using JYStockAnalyser.ClientLib;

namespace JYStockAnalyser.WinUI
{
    public partial class FrmCompoundGrowthRateComputer : Form
    {
        public FrmCompoundGrowthRateComputer()
        {
            InitializeComponent();
        }

        private void btnCompute_Click(object sender, EventArgs e)
        {
            string strPeriod = this.txtPeriod.Text.Trim();
            string strBeginValue = this.txtBeginValue.Text.Trim();
            string strEndValue = this.txtEndValue.Text.Trim();
            string strCompoundGrowthRate = this.txtCompoundGrowthRate.Text.Trim();

            int nullCount = 0;
            if (string.IsNullOrEmpty(strPeriod))
                nullCount += 1;
            if (string.IsNullOrEmpty(strBeginValue))
                nullCount += 1;
            if (string.IsNullOrEmpty(strEndValue))
                nullCount += 1;
            if (string.IsNullOrEmpty(strCompoundGrowthRate))
                nullCount += 1;

            if (nullCount != 1 || string.IsNullOrEmpty(strCompoundGrowthRate))
            {
                Tool.ShowInformationBox("请输入复利计算期与其它两项数据，空出的一项系统自动计算");
            }

            if (string.IsNullOrEmpty(strCompoundGrowthRate))
            {
                this.txtCompoundGrowthRate.Text = ((Math.Pow((double)(double.Parse(this.txtEndValue.Text) / double.Parse(this.txtBeginValue.Text)), (double)(1d / double.Parse(this.txtPeriod.Text))) - 1) * 100).ToString("0.00");
            }

            //if (string.IsNullOrEmpty(strBeginValue))
            //{
            //    Math.po
            //}
        }

        private void FrmCompoundGrowthRateComputer_Load(object sender, EventArgs e)
        {

        }
    }
}
